import React from 'react';
import { Button, Header, ResumeForm, SignResult } from '@/pages/RecruitEmail/mobile/components';
import { createForm } from 'rc-form';
import pic from '@/pages/RecruitEmail/images/interview-bg-accept.png';
import { Toast, ActivityIndicator } from 'antd-mobile';
import { querySignIn, getSignInData } from '@/pages/RecruitEmail/service';
import { useRequest, defaultFormatResult } from '@/hooks';
import MetaTags from 'react-meta-tags';
import { pushRoute } from '@/pages/RecruitEmail/utils';
import styles from './index.less';
// 废弃
function InterviewSign({ form, id, nid }) {
    // const pageStyle = {
    //     minHeight: '100%',
    //     background: '#fff'
    // };
    const handleCheck = () => {
        pushRoute({
            pathname: '/recruitment/register',
            query: {
                id,
                nid
            }
        });
    };
    const { data: signData, loading } = useRequest(() => getSignInData(nid), {
        ...defaultFormatResult
    });

    const handleSubmit = () => {
        form.validateFields(async (errors, values) => {
            if (errors) {
                // Toast.fail(errors[0]);
                return;
            }
            try {
                // setSubmitLoading(true);
                Toast.loading('提交中...', 5000);
                const { data, code, msg } = await querySignIn({
                    phone: values.phone
                });
                if (code === 10000 && data && JSON.stringify(data) !== '{}') {
                    Toast.success('签到成功!');
                    // history.push({
                    //     pathname: '/external/interview/signInResult',
                    //     query: {
                    //         id: data
                    //     }
                    // });
                } else {
                    Toast.info(msg);
                }
                // setSubmitLoading(false);
            } catch (e) {
                Toast.fail('网络异常，签到失败');
                // setSubmitLoading(false);
            }
        });
    };
    return (
        <div className={styles.pageWrap}>
            <div style={{ position: 'relative', paddingBottom: 24 }}>
                <MetaTags>
                    <title>微微科技官网</title>
                    <meta name="keywords" content="微微科技官网" />
                    <meta name="description" content="微微科技官网" />
                    <meta
                        name="viewport"
                        content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"
                    />
                </MetaTags>
                {/* 正常状态 */}

                <>
                    <div style={{ position: 'absolute', left: 0, top: 0, right: 0, zIndex: 99 }}>
                        <Header />
                        <ActivityIndicator animating={loading} />
                    </div>
                    <div>
                        <>
                            <div className={styles.header}>
                                <div className={styles.resultWrap}>
                                    <div className={styles.resultTitle}>欢迎加入 微微科技有限公司</div>
                                    <div className={styles.resultContent}>请进行入职签到</div>
                                </div>
                                <img src={pic} alt="" className={styles.pic} />
                            </div>

                            <div className={styles.hdiv}></div>
                            <div className={styles.form}>
                                <ResumeForm form={form} />
                                <div className={styles.btn}>
                                    <Button type="primary" onClick={handleSubmit}>
                                        提交
                                    </Button>
                                </div>
                            </div>
                        </>
                        <>
                            <div className={styles.resultWrap}>
                                <SignResult data={signData?.arrangeVO} handleCheck={handleCheck} />
                            </div>
                        </>
                    </div>
                </>
            </div>
        </div>
    );
}

export default createForm()(InterviewSign);
